#include<stack>
using namespace std;
class MinStack {
public:
    MinStack() {

    }

    void push(int val) {
        _stack.push(val);
        if (_min_stack.empty() || val <= _min_stack.top()) {
            _min_stack.push(val);
        }
    }

    void pop() {
        int val = _stack.top();
        _stack.pop();
        if (!_min_stack.empty() && val == _min_stack.top()) {
            _min_stack.pop();
        }
    }

    int top() {
        return _stack.top();
    }

    int getMin() {
        return _min_stack.top();
    }
private:
    stack<int> _stack;
    stack<int> _min_stack;
};
